<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>站点管理</title>
    <#assign base=request.contextPath  />
    <base id="basePath" href="${base}">
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/frame/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>
    <script src="${base}/js/zhang.js"></script>
    <style type="text/css">
        .layui-btn-radius{
            border-radius: 5px;
        }
    </style>
</head>
<body>
<div class="demoTable"style="padding:15px;">
    <button class="layui-btn" id="btn2" data-method="offset"  type="button" style="background-color: #0092EF;">添加站点</button>
</div>
<table class="layui-hide" id="test"  lay-filter="test"></table>
<script type="text/html" id="barDemo">

    <button type="button"  class="layui-btn layui-btn-sm layui-btn-normal"
            lay-event="edit" style="background: #28B779;width: 60px;">编辑
    </button>

    <#--<i class="layui-icon layui-icon-edit" lay-event="edit" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;-->
    <button type="button" onclick="onDelete('{{d.id}}')" class="layui-btn layui-btn-sm layui-btn-normal"
            lay-event="del" style="background: red;width: 60px;">删除
    </button>
</script>
<script>
    layui.use(['form', 'layedit', 'laydate', 'table', 'carousel'], function () {

        var carousel = layui.carousel;
        var form = layui.form
            , $ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        table.render({
            elem: '#test'
            ,url:'${base}/admin/site/selectMyPage'
            ,title: '站点管理'
            ,totalRow: true
            ,toolbar: '#toolbarDemo'//打印
            ,cols:[[
                {field:'id', title: '序号',templet:function(val){
                        return val.LAY_INDEX
                    }, field: true,align:'center'}
                ,{field:'name', title: '名称', align:'center'}
                ,{field:'address', title: '地址', align:'center'}
                ,{field:'brand', title: '所属品牌', align:'center'}
                ,{field:'longitude', title: '经度', align:'center'}
                ,{field:'dimension', title: '维度', align:'center'}
                ,{field:'discount', title: '优惠信息', align:'center'}
                ,{field:'createTime', title: '创建时间',templet:function(val){
                        if(val.createTime==undefined){
                            return "";
                        }
                        return changeDateFormat(val.createTime);
                    },  align:'center'}
                ,{field: 'right', title:'操作',toolbar: '#barDemo', align:'center'}
            ]]
            ,id:'testReload'
            ,height:720
            ,page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                ,theme: '#0092EF'
                ,limit:10
            }
            ,done: function(res, curr, count){
                this.where={};
            }
        });

        var active = {
            offset: function (othis) {
                var type = othis.data('type')
                        , text = othis.text();
                layer.open({
                    type: 2,
                    title: '添加站点',
                    area: ['600px', '600px'], //高 宽
                    shadeClose: false,
                    //弹出的页面路径
                    content: '${base}/admin/site/site_add.html',//路径

                });
            }
        };

        $('#btn2').on('click', function(){
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });

        //编辑弹出层
        table.on('tool(test)', function (obj) {
            var layEvent = obj.event;
            if (layEvent == "edit") {
                var data = obj.data;
                //示范一个公告层
                layer.open({
                    type: 2,
                    title: '修改站点',
                    shadeClose: false,
                    area: ['600px', '600px'],
                    content: '${base}/admin/site/site_edit.html?id='+data.id,
                    success: function (layero, index) {
                        var iframeWin = window[layero.find
                        ('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.$("#name").val(data.name)
                        iframeWin.$("#address").val(data.address)
                        iframeWin.$("#latlng").val("经度:"+data.longitude+","+"维度:"+data.dimension)

                        iframeWin.$("#brand").val(data.brand)
                        iframeWin.$("#discount").val(data.discount)
                        iframeWin.$("#id").val(data.id)
                        //渲染一下form表单
                        iframeWin.layui.form.render('select')
                    }
                });
            }
        });



    });

    //删除
    function onDelete(id){
//提示是否删除这条数据
//data里边的customerId是需要和实体类里边的id是一样的,不然是传不过来参数的
        layer.confirm('真的要删除吗?',function(index){
            var data = {};
            data.id = id;
            $.ajax({
                type:"POST",
                contentType: "application/json;charset=UTF-8",
                url:"${base}/admin/site/deleteByIdSite",
                data:JSON.stringify(data),
                sync:false,
                success:function(data){
                    if(data.code === 200){
                        layer.msg(data.msg)
                        var table = layui.table;
                        //表刷新方法
                        table.reload('testReload', {
                            url:'${base}/admin/site/selectMyPage'
                            ,where: {} //设定异步数据接口的额外参数
                        });
                        //关闭删除是否删除的提示框
                        layer.close(index);
                    }else{
                        layer.msg(data.msg)
                    }

                }
            });
        });
    }

</script>

</body>
</html>